﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
namespace hoangnam12
{
    public partial class DangNhap : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public void ShowMessage(string Content)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script language='javascript'>alert('" + Content + "');location.href = 'DangNhap.aspx'</script>");
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            dataprovider data = new dataprovider();
            string EncodePwd = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text, "MD5");
          
            string sql = "select Username, Password from [User] where Username = '" + TextBox1.Text + "' and Password = '" + EncodePwd + "'";
            if (data.ExecuteReader(sql).HasRows)
            {
                ShowMessage("Bạn Đã Đăng Nhập Thành Công");
                Session["login"] = TextBox1.Text;
                Response.Redirect("Default.aspx");
            }
            else
            {
                ShowMessage("Không Đúng Username Hoặc Password");
                //Response.Redirect("DangNhap.aspx");
            }
            
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            Response.Redirect("DangKy.aspx");
        }
    }
}